﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Media.Media3D;

namespace FeatureDetection.Inputter {
    //TODO FileInputter未実装
    class FileInputter : IInputter{
        private Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

        public override bool initialize() {
            dlg.FileName = "*.csv";
            dlg.DefaultExt = "*.csv";
            dlg.Filter = "CSVドキュメント(*.csv)|*.csv";
            if(dlg.ShowDialog() == true) {  return true;}
            else{return false;}
        }

        public override void startInput(IInputter.AddPosition addpos, IInputter.EndFunc endFunc) {
            //適切なファイル名が選択された
            using(var s = new StreamReader(dlg.OpenFile())) {
                while(!s.EndOfStream) {
                    var line = s.ReadLine().Split(',');
                    addpos(new Vector3D(double.Parse(line[1]), double.Parse(line[2]), double.Parse(line[3])));
                }
            }
            endFunc();
        }

        public override void endInput() {
        }
    }
}
